package com.example.myapplication;

import androidx.annotation.Nullable;

import android.annotation.SuppressLint;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.myapplication.dao.MySQLiteOpenHelper;
import com.example.myapplication.databinding.Activity2MainPersonalBinding;
import com.example.myapplication.pages.pageActivity;
import com.example.myapplication.service.SharedPreferencesService;

import java.util.Map;

public class MainActivityPersonal extends Fragment {
    private Activity2MainPersonalBinding personalBinding;
    private MySQLiteOpenHelper mySQLiteOpenHelper;

    @SuppressLint("SetTextI18n")
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        personalBinding = Activity2MainPersonalBinding.inflate(inflater, container, false);
        Map<String, Object> userInfo = SharedPreferencesService.getUserInfo(this.getContext());
        personalBinding.name.setText((String) userInfo.get("account"));
        onClick();
        mySQLiteOpenHelper = new MySQLiteOpenHelper(getContext());
        /*记录条数*/
        Integer userId = (Integer) userInfo.get("userId");
        personalBinding.grShm.setText("" + mySQLiteOpenHelper.queryPersonByCondition(0, null, null, userId).size());

        return personalBinding.getRoot();
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public void onClick() {
        /*预算中心*/
        personalBinding.budgetBtn.setOnClickListener(view -> {
            Intent intent = new Intent(getContext(), pageActivity.class);
            startActivity(intent);
        });
        /*使用帮助*/
        personalBinding.usehelpBtn.setOnClickListener(view -> {
            Toast.makeText(getContext(), "功能未开放", Toast.LENGTH_SHORT).show();
//                Intent intent = new Intent(getContext(), Activity2Help.class);
//                startActivity(intent);
        });
        /*关于我们*/
        personalBinding.aboutBtn.setOnClickListener(view -> {
            Toast.makeText(getContext(), "关于我们", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(getContext(), MainActivity2About.class);
                startActivity(intent);
        });
        /*修改密码*/
        personalBinding.settingBtn.setOnClickListener(view -> {
            Intent intent = new Intent(getContext(), MainActivityUpdate.class);
            startActivity(intent);
        });

        /*退出登录*/
        personalBinding.grTch.setOnClickListener(view -> {
            Intent intent = new Intent(getContext(), MainActivityLogin.class);
            startActivity(intent);
            SharedPreferencesService.deleteUserInfo(getContext());
            getActivity().finish();
        });
    }


    @Override
    public void onResume() {
        super.onResume();
    }

}